package Kuang;

import java.util.Locale;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.08.19.36
 */
public class Demo4 implements Runnable{
    //票数
    final Object lock=new Object();
    private int ticketNum=10;
    @Override
    public  void run() {
        String tn=Thread.currentThread().getName();

    while (true) {
        synchronized (lock) {
        if (ticketNum <= 0) {
            // System.out.println(tn+"票已售完");
            break;
        }
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(tn + "--->拿到了第" + ticketNum-- + "票");
    }
}
    }

    public static void main(String[] args) {
        Demo4 t=new Demo4();
        new Thread(t,"老师").start();
        new Thread(t,"小明").start();
        new Thread(t,"黄牛党").start();
    }
}
